//
//  JXSearchBar.swift
//  weibo
//
//  Created by admin on 16/5/19.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit

class JXSearchBar: UIView {

	@IBOutlet weak var searchTextField: JXTextField!

	@IBOutlet weak var cancelBtn: UIButton!

	@IBOutlet weak var rightConstraint: NSLayoutConstraint!
    @IBAction func cancelBtnClick(sender: AnyObject) {


		UIView.animateWithDuration(0.25) {

			self.rightConstraint.constant = 0
			self.searchTextField.endEditing(true)
            
            self.layoutIfNeeded()
		}

	}

	@IBAction func textFieldClick(sender: AnyObject) {

		UIView.animateWithDuration(0.25) {

			self.rightConstraint.constant = self.cancelBtn.bounds.width + 10
			self.layoutIfNeeded()
		}

	}
	// 类方法中,加载xib

	class func loadSearchBar() -> JXSearchBar {

		let bar = NSBundle.mainBundle().loadNibNamed("JXSearchBar", owner: nil, options: nil).last as! JXSearchBar

		return bar

	}

	// 设置左边视图(搜索小图)

	override func awakeFromNib() {

		searchTextField.leftView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
		// 设置显示模式
		searchTextField.leftViewMode = .Always

		// 设置frame
		searchTextField.leftView?.frame = CGRect(x: 0, y: 0, width: 40, height: 40)

		// 显示模式
		searchTextField.leftView?.contentMode = .Center
        
//        //设置搜索栏圆角
//        searchTextField.layer.cornerRadius = 15;
//        searchTextField.layer.masksToBounds = true
//
//        //设置边线颜色,边线宽度
//        searchTextField.layer.borderColor = UIColor.orangeColor().CGColor
//        searchTextField.layer.borderWidth = 2
	}

}
